package com.bw.search.server.controller;


import com.bw.common.core.domain.R;
import com.bw.search.server.service.ProductService;
import com.bw.search.server.vo.SearchParam;
import com.bw.search.server.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/search")
public class EsSearchController
{


    @Autowired
    private ProductService productService;

    @GetMapping("/product")
    public R<SearchResult> searchProduct(SearchParam searchParam){
        try {
            SearchResult result = productService.search(searchParam);
            return R.ok(result);
        } catch (IOException e) {
            return R.fail(e.getMessage());
        }
    }
}
